package com.isp.org.server.application.facade;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.isp.org.api.dto.user.UserVO;
import com.isp.org.server.domain.entity.UserEntity;
import com.isp.org.server.domain.service.MenuService;
import com.isp.org.server.domain.service.RoleUserService;
import com.isp.org.server.domain.service.UserService;
import com.isp.org.server.interfaces.model.user.mapper.UserMapStruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author linsy
 * @version 1.0
 * @created 2024/3/13 14:35
 */
@Service
@RequiredArgsConstructor
public class UserFacade {

    private final UserService userService;
    private final RoleUserService roleUserService;


    @Cached(name = "user::", key = "#uniqueId", cacheType = CacheType.BOTH)
    public UserVO getByUniqueId(String uniqueId) {
        UserEntity user = userService.getByUniqueId(uniqueId);
        UserVO userVo = UserMapStruct.INSTANCE.entityToVo(user);
        userVo.setRoleIds(roleUserService.queryByUserId(user.getId()));
        return userVo;
    }
}
